(import
 (except (rnrs base)
         let-values
         map
         error
         vector-map)
 (only (guile)
       lambda* λ
       simple-format
       current-output-port)

 ;; standard library
 (ice-9 pretty-print)

 ;; custom modules
 (fileio)
 (pipeline)
 (debug)
 (list-helpers)

 ;; hash tables
 (srfi srfi-69)
 ;; let-values
 (srfi srfi-11)

 ;; graph algos
 (a-star)
 (dijkstra)

 ;; distances
 (prefix (distances) distance:)

 (graph-model)
 (graph-reader)
 (graph-utils)
 )


;; (define input-filename "example-graphs/graph-01.txt")
(define input-filename "example-graphs/graph-01.txt")

(define-values (nodes distances-table nodes-table)
  (read-graph input-filename))

(simple-format #t "node names: ~s\n" (hash-table-keys nodes-table))

(define manhattan-node-distance
  (λ (source-node target-node)
    (distance:manhattan (node-y source-node)
                        (node-y target-node)
                        (node-x source-node)
                        (node-x target-node))))

(define get-node-distance
  (λ (source-node-name target-node-name)
    (hash-table-ref distances-table
                    (cons source-node-name
                          target-node-name))))

(let ([start-node (hash-table-ref nodes-table "A")]
      [target-node (hash-table-ref nodes-table "O")])
  (pretty-print
   (routes->path (A* start-node
                     target-node
                     (hash-table-keys nodes-table)
                     nodes-table
                     get-node-distance
                     manhattan-node-distance
                     <)
                 (node-name target-node)
                 #:equal-test string=?)))
